<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Student_model extends CI_Model{
	
	
	public function view_info(){	
		$this->load->database();
		$this->load->library('session');
		
		//temporary lang imomove sa login kapag ngmerge
		$userdata = array('student_no' => '2010-34687');
		$this->session->set_userdata($userdata);
		
		$key = $this->session->userdata('student_no');
		
		$student = $this->db->query("select * from student where Student_No like '".$key."'");
		
		return $student->result();
	}
	
	public function advisers($type){
		$this->load->database();
		$this->load->library('session');
		
		//temporary lang imomove sa login kapag ngmerge
		$userdata = array('student_no' => '2010-34687');
		$this->session->set_userdata($userdata);
		
		$key = $this->session->userdata('student_no');
		
		if($type == 'sp'){
			$table = 'sp_advisee';
		}else if($type == 'reg'){
			$table = 'reg_advisee';
		}
		
		$student = $this->db->query("SELECT i.first_name,i.middle_name, i.last_name,i.designation_rank,i.email_address,i.faculty_room from instructor i,".$table." r where r.student_no_student like '".$key."' and r.employee_no_instructor like i.employee_no");
		
		return $student->result();
	}
	
	public function edit_basicinfo(){
		$this->load->database();
		$this->load->library('session');
		
		//temporary lang imomove sa login kapag ngmerge
		$userdata = array('student_no' => '2010-34687');
		$this->session->set_userdata($userdata);
		
		$key = $this->session->userdata('student_no');
		
		$mobile_no = $this->input->post('MOBILE_NO');
		$home_address = $this->input->post('HOME_ADDRESS');
		$home_contact = $this->input->post('HOME_CONTACT');
		$coll_add  = $this->input->post('COLLEGE_ADDRESS');
		$coll_contact = $this->input->post('COLLEGE_CONTACT');
		$curriculum = $this->input->post('CURRICULUM_TAKEN');
		$photo = $this->input->post('PHOTO');
		
		$result = $this->db->query("
			UPDATE student SET Mobile_No = 0".$mobile_no.",
				Home_Address = '".$home_address."',
				Home_Contact = '".$home_contact."',
				College_Address = '".$coll_add."',
				College_Contact = '".$coll_contact."',
				Curriculum_Taken = '".$curriculum."',
				Photo = '".$key.".JPG'
			WHERE Student_No = '".$key."'
		");
	}
	
	public function view_acadhist(){
		$this->load->database();
		$this->load->library('session');
		
		//temporary lang imomove sa login kapag ngmerge
		$userdata = array('student_no' => '2010-34687');
		$this->session->set_userdata($userdata);
		
		$key = $this->session->userdata('student_no');
		
		$acadhist = $this->db->query("SELECT * from academic_history where Student_No like '".$key."'");
		
		return $acadhist->result();
	}
}